package dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import util.DBUtil;

import model.TrainProperty;
import model.TrainType;
import dao.TrainPropertyDAO;

public class TrainPropertyDAOImpl implements TrainPropertyDAO {
	DBUtil dbu = new DBUtil();
	Connection conn = null;
	PreparedStatement pstat = null;
	ResultSet rs = null;
	public List<TrainProperty> getAll() {
		List<TrainProperty> list = new ArrayList<TrainProperty>();
		try {
			conn = dbu.getConnection();
			String sql = "select * from TRAINPROPERTY";
			pstat = conn.prepareStatement(sql);
			rs = pstat.executeQuery();
			while (rs.next()) {
				TrainProperty tp = new TrainProperty();
				tp.setId(rs.getInt("ID"));
				tp.setPropertyname(rs.getString("PROPERTYNAME"));
				list.add(tp);
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			dbu.closeConnection(conn, pstat, rs);
		}
		return list;
	}

	public TrainProperty getById(int id) {
		ResultSet rs = null;
		TrainProperty tp=null;
			try {
				conn = dbu.getConnection();
				String sql = "select * from TRAINPROPERTY";
				pstat = conn.prepareStatement(sql);
				rs = pstat.executeQuery();
				while (rs.next()) {
					tp = new TrainProperty();
					tp.setId(rs.getInt("ID"));
					tp.setPropertyname(rs.getString("PROPERTYNAME"));
					
				}
			} catch (Exception e) {
				e.printStackTrace();
			} finally {
				dbu.closeConnection(conn, pstat, rs);
			}
			return tp;
	}

	public TrainProperty getByName(String name) {
		// TODO Auto-generated method stub
		return null;
	}

}
